import { getAreaObj } from '@/utils/util'

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '设备信息',
			span: 24,
		},
		{
			label: '设备名称',
			prop: 'equipmentName',
			type: 'input',
			maxlength: '100',
			showWordLimit: true,
			span: 12,
			rules: [{ required: true, message: '请输入设备名称' }],
		},
		{
			label: '设备编号',
			prop: 'equipmentNo',
			type: 'input',
			maxlength: '100',
			showWordLimit: true,
			span: 12,
			rules: [{ required: true, message: '请输入设备编号' }],
		},
		{
			label: '设备类型',
			prop: 'equipmentType',
			propName: 'equipmentTypeLabel',
			type: 'remoteSelect',
			code: 'EQUIPMENT_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			changeField: true,
			dataType: 'string',
			rules: [{ required: true, message: '请选择设备类型' }],
			span: 8,
		},
		{
			label: '使用机构',
			prop: 'organizationId',
			propName: 'organizationName',
			type: 'remoteSelect',
			api: 'view_dpServiceOrgBase_page',
			filterKey: 'creditCode',
			filterLabel: 'organizationName',
			multiple: false,
			rules: [{ required: true, message: '请选择当前使用机构' }],
			span: 8,
		},
		{
			label: '状态',
			prop: 'equipmentStatus',
			type: 'select',
			dicData: [
				{ label: '空闲', value: 1 },
				{ label: '使用中', value: 2 },
			],
			span: 8,
		},
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '安装信息',
			span: 24,
		},
		{
			label: '安装人',
			prop: 'installUser',
			type: 'input',
			span: 12,
		},
		{
			label: '安装时间',
			prop: 'installTime',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 12,
		},
	],
}


export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '设备编号', prop: 'equipmentNo' },
		{ label: '设备名称', prop: 'equipmentName' },
		{ label: '设备类型', prop: 'equipmentTypeLabel' },
		{
			label: '设备状态',
			prop: 'equipmentStatus',
			custome: 'tag',
			dicData: [
				{ label: '空闲', value: 1 },
				{ label: '使用中', value: 2 },
				{ label: '维修中', value: 3 },
				{ label: '报废', value: 4 },
			],
		},
		{
			label: '在线状态',
			prop: 'onlineStatus',
			custome: 'tag',
			dicData: [
				{ label: '在线', value: 1 },
				{ label: '离线', value: 2 },
			],
		},
		{ label: '养老机构', prop: 'organizationName' },
		{
			label: '操作',
			prop: 'menu',
			width: 100,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_dotEquipment_page',
	// add: 'view_dotEquipment_add',
	// edit: 'view_dotEquipment_edit',
	// delete: 'view_dotEquipment_del',
	// export: 'view_dotEquipment_export',
}
export const baseConfig = {
	pageName: '智能设备管理',
	dictcodes: ['EQUIPMENT_TYPE'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'equipmentNo',
	exportMqTopic: '/ning/export/',
	api,
	auth: {
		...api,
		// mulitSet: 'mulitSet',
	},
	paramsObj: {
		source: 1,
	},
	menuBtn: [
		{
			icon: 'detail',
			label: '查看',
			type: 'primary',
			operate: 'detail',
			auth: api.index,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '55%',
	},
	// searchConfig,
	// formConfig,
	tableConfig,
	detailConfig: formConfig,
	beforeOnLoadFormate: async (params) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(params.areas)
			resolve({
				...params,
				...areaObj,
				areas: undefined,
			})
		})
	},
}
